package com.dkt.android.mvp.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.vlayout.DelegateAdapter
import com.alibaba.android.vlayout.LayoutHelper
import com.alibaba.android.vlayout.VirtualLayoutManager
import com.alibaba.android.vlayout.layout.LinearLayoutHelper
import com.dkt.android.R
import com.dkt.android.base.BaseFragment
import com.dkt.android.core.RouterHub
import com.dkt.android.mvp.model.BannerBean
import com.dkt.android.mvp.model.IndexShopBean
import com.dkt.android.mvp.ui.adapter.IndexBannerAdapter
import com.dkt.android.mvp.ui.adapter.IndexShopAdapter
import com.dkt.android.utils.Utils
import com.dtb.utils.commons.toast.Tnormal
import java.text.Normalizer

@Route(path = RouterHub.APP_INDEX)
class IndexFragment : BaseFragment(){

    private var mainAdapter: DelegateAdapter? = null
    private var indexBannerAdapter: IndexBannerAdapter? = null
    private var indexShopAdapter: IndexShopAdapter? = null
    private val bannerList = mutableListOf<BannerBean>()
    private val shopList = mutableListOf<IndexShopBean>()

    override fun onCreateView(
            inflater: LayoutInflater, container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.public_base_ry, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initData()
        initView(view)

    }

    private fun initView(view: View){
        val layoutManager = VirtualLayoutManager(this@IndexFragment.activity!!)
        val baseRy = view.findViewById<RecyclerView>(R.id.baseRy)
        mainAdapter = DelegateAdapter(layoutManager, false)

        indexBannerAdapter = IndexBannerAdapter(bannerList, LinearLayoutHelper() as LayoutHelper)
        indexShopAdapter=IndexShopAdapter(shopList, LinearLayoutHelper() as LayoutHelper)
        indexShopAdapter?.setOnListener { position, _, _ ->
            activity?.Tnormal("进入第${position+1}个商铺")
            Utils.navigation(this@IndexFragment.activity!!, RouterHub.APP_MAP_ACTIVITY)
        }
        mainAdapter?.addAdapter(indexBannerAdapter)
        mainAdapter?.addAdapter(indexShopAdapter)
        baseRy?.layoutManager = layoutManager
        baseRy?.adapter = mainAdapter
    }

    private fun initData(){
        bannerList.add(BannerBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1591956319863&di=43ab55dbe5457e476bbc8b331967dc49&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Fe%2F539a6f50d8285.jpg"))
        bannerList.add(BannerBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1591956288667&di=d19b7f569137950e0c28e4b7467b6ece&imgtype=0&src=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Farticle%2Fbb7390927d33e27477bc8b4f5be0ea84a3f8b3fc.jpg"))
        bannerList.add(BannerBean("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2626220075,3060584915&fm=26&gp=0.jpg"))

        shopList.add(IndexShopBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1591956319863&di=43ab55dbe5457e476bbc8b331967dc49&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Fe%2F539a6f50d8285.jpg",
            "京东","【2020夏季新款】茵曼短袖T恤圆领纯棉文艺绣花修身显瘦百搭上衣【1802003】 暗绿色-1802192 M","15.6W粉丝","查看店铺地图 >"))
        shopList.add(IndexShopBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1591956288667&di=d19b7f569137950e0c28e4b7467b6ece&imgtype=0&src=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Farticle%2Fbb7390927d33e27477bc8b4f5be0ea84a3f8b3fc.jpg",
            "淘宝","惠普(HP)战66 商用办公台式电脑主机（九代i3-9100 8G 1TB Win10 Office WiFi蓝牙 四年上门）21.5英寸","153.6W粉丝","查看店铺地图 >"))
        shopList.add(IndexShopBean("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2626220075,3060584915&fm=26&gp=0.jpg",
            "天猫","【官方典藏限量版 直降2800】【头层牛皮 手工定制】沙滩鞋男士防滑耐磨包头防撞套脚户外登山凉鞋 暗棕色 41","315.6W粉丝","查看店铺地图 >"))

    }
}